//
//  CustomAnnotationView.m
//  ConvenientlyTake
//
//  Created by 张奇 on 2023/1/10.
//

#import "CustomAnnotationView.h"

#define kCalloutWidth       145.0
#define kCalloutHeight      45.0
@interface CustomAnnotationView ()

@property (nonatomic, strong, readwrite) CustomCalloutView *calloutView;

@end

@implementation CustomAnnotationView

- (id)initWithAnnotation:(id<MAAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]) {
        if (self.calloutView == nil)
        {
            self.calloutView = [[CustomCalloutView alloc] initWithFrame:CGRectMake(0, 0, kCalloutWidth, kCalloutHeight)];
            self.calloutView.center = CGPointMake(CGRectGetWidth(self.bounds) / 2.f + self.calloutOffset.x,
                                                  -CGRectGetHeight(self.calloutView.bounds) / 2.f + self.calloutOffset.y);
        }
        
        self.calloutView.image = [UIImage imageNamed:@"common_placehoder"];
        self.calloutView.title = annotation.title;
        self.calloutView.subtitle = annotation.subtitle;
        
        [self addSubview:self.calloutView];
    }
    return self;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
//    if (self.selected == selected)
//    {
//        return;
//    }
    
//    if (selected)
//    {
//        if (self.calloutView == nil)
//        {
//            self.calloutView = [[CustomCalloutView alloc] initWithFrame:CGRectMake(0, 0, kCalloutWidth, kCalloutHeight)];
//            self.calloutView.center = CGPointMake(CGRectGetWidth(self.bounds) / 2.f + self.calloutOffset.x,
//                                                  -CGRectGetHeight(self.calloutView.bounds) / 2.f + self.calloutOffset.y);
//        }
//
//        self.calloutView.image = [UIImage imageNamed:@"common_placehoder"];
//        self.calloutView.title = self.annotation.title;
//        self.calloutView.subtitle = self.annotation.subtitle;
//
//        [self addSubview:self.calloutView];
//    }
//    else
//    {
//        [self.calloutView removeFromSuperview];
//    }
    
    [super setSelected:selected animated:animated];
}


@end
